<template>
	<view v-if="hotWorks.length > 0">
		<fui-collapse-item v-for="(item,index) in hotWorks" :key="index" :title="'设备编号：' +  item.deviceNumber ">
			<view class="fui-item__box">
				<!-- <image src="@/static/user_selct.png" class="fui-logo"></image> -->
				<text>上传日期：{{item.creationTime}}</text>
			</view>
			<template v-slot:content>
				<fui-input readonly @click="onPreview(item.hotWorkCertificate)" value="已上传" label="查看证书:" ></fui-input>
				<fui-input readonly :value="item.state" label="状态" borderTop></fui-input>
				<fui-input readonly :value="item.startTime + ' 至 ' + item.endTime " label="有效日期:" borderTop></fui-input>
				<fui-input readonly :value="item.timePeriodStarts + ' 至 ' + item.end_of_time_period " label="每天有效时段:" borderTop></fui-input>
				<view v-if="item.securityOperatorsUserSignature">
					<fui-input readonly :value="item.securityOperatorsUserNickname" label="安全管理操作员:" borderTop></fui-input>
					<fui-input readonly @click="onPreview(item.securityOperatorsUserSignature)" value="已签名"  label="签名:" borderTop></fui-input>
					<fui-input readonly :value="item.securityOperatorsUserTime" label="签名时间:" borderTop></fui-input>
				</view>
				<view v-if="!item.securityOperatorsUserSignature">
					<fui-input readonly value="无" label="安全管理操作员:" borderTop></fui-input>
					<fui-input readonly value="未签名"  label="签名:" borderTop></fui-input>
					<fui-input readonly value="无" label="签名时间:" borderTop></fui-input>
				</view>
				<view  v-if="item.unitLeaderUserSignature">
					<fui-input readonly :value="item.unitLeaderUserNickname" label="单位负责人:" borderTop></fui-input>
					<fui-input readonly @click="onPreview(item.unitLeaderUserSignature)" value="已签名" label="签名:" borderTop></fui-input>
					<fui-input readonly :value="item.unitLeaderUserTime" label="签名时间:" borderTop></fui-input>
				</view>
				<view  v-if="!item.unitLeaderUserSignature">
					<fui-input readonly value="无" label="单位负责人:" borderTop></fui-input>
					<fui-input readonly value="未签名" label="签名:" borderTop></fui-input>
					<fui-input readonly value="无" label="签名时间:" borderTop></fui-input>
				</view>
				
			</template>
		</fui-collapse-item>
	</view>
	<view v-else style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;">
		<view style="width: 80rpx; height: 80rpx;">
			<up-empty mode="data">
			</up-empty>
		</view>
	</view>
</template>

<script>
	import {
		BASE_IP
	} from '@/common/http/url.js'
	export default {
		data() {
			return {
				hotWorks: []
			}
		},
		onLoad() {
			this.queryServiceDatas()
		},
		methods: {
			onPreview(url) {
				console.log(url)
				const regex = /\.(pdf)$/i;
				const regexv = /\.(jpg|png|jpeg)$/i;
				const matchPdf = regex.test(url);
				const matchPdfv = regexv.test(url);
				if (matchPdf) {
			
					let urls = BASE_IP + url
					// console.log(urls)
					let filelist = {
						name: '预览',
						fileSrc: urls,
						isFileDown: true
					}
					uni.navigateTo({
						url: "/pages/common/fileView",
						success: (res) => {
							// 通过eventChannel向被打开页面传送数据
							res.eventChannel.emit("dataFun", {
								data: filelist,
							});
						},
					});
				} else if (matchPdfv) {
					uni.showLoading({
						title: "正在加载"
					})
					let urls = BASE_IP + url
					console.log(urls)
					let arr = []
					arr.push(urls)
					uni.previewImage({
						urls: arr,
						current: arr.length,
						success(r) {
							uni.hideLoading();
							console.log(r)
						},
						fail() {
							uni.hideLoading();
							uni.showToast({
								title: "加载失败",
								icon: "error"
							})
						}
					})
				}
			},
			queryServiceDatas() {
				let url = BASE_IP + "pc/hot/work/get/unit/list"
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					success: (res) => {
						console.log(res)
						if(res.statusCode == 200){
							if(res.data.code ==1){
								this.hotWorks =[]
								this.hotWorks = res.data.data
							}
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
.fui-item__box {
		width: 100%;
		padding: 26rpx 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.charts-user-list-son {
		width: 95%;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		margin: 0 auto;
	}
</style>